#include <iostream>
#include <fstream>
#include <filesystem>
#include <cstring>
#include <cstdlib>
#include "HEMUIRCode.h"
#include "HEMUIRParse.h"
#include "HEMUMem.h"
//#include "HEMUHdb.h"


HEMUIRFTb func_tb;
HEMUIRFInsTb func_inst_tb;
HEMUIRGloTb glo_tb;
HEMUStack stack;
HEMUGMem gmem;
HEMUIRCode hemu_code;


int main(int argc, const char* argv[]) {
	std::ifstream fin;
	std::istream* pis;
	const char* filename = NULL;
	//const char* exename = argv[0];
	bool hdb = false;

	while (--argc) {
		++argv;
		if (strcmp("-hdb", *argv) == 0) {
			hdb = true;
		}
		else {
			filename = *argv;
		}
	}

	if (filename == NULL) {
		pis = &std::cin;
	}
	else {
		fin.open(filename);
		if (!fin.is_open()) {
			exit(EXIT_FAILURE);
		}
		pis = &fin;
	}
	std::cout << "bbl loader" << std::endl;
	hemu_code = HEMUIRCode(*pis, hdb);
	HEMUIRVar res = hemu_code.executor(hdb);
	// res.print_var();
	std::cout << res.val.i32_val << std::endl;
	return res.val.i32_val == 0 ? 0 : 1;
}








